<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>诉讼申请(设备账单)</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="sqPanel" style="margin-bottom: 5px;">
        <div class="sqPanel_head" style="height:35px;">
            <table class="table_full">
                <tr>
                    <td><span >---诉讼申请单---</span></td>
                </tr>
            </table>
        </div>
    </div>
    <form id="addAcc_form">
        <input name="lawyerId" id="lawyerId" type="hidden" class="ui-textbox" value=""  >
        <input name="lawyerNm" id="lawyerNm" type="hidden" class="ui-textbox" value="" >

        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_33">
                <div class="label">申请人</div>
                <div class="field">
                    <input name="applyerNm" id="applyerNm" disabled="disabled" type="text" data-type="text" class="ui-textbox" value="${usrNm}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请人电话</div>
                <div class="field">
                    <input name="applyerPhone" id="applyerPhone" type="text" class="ui-textbox" value="" >
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">申请时间</div>
                <div class="field">
                    <input name="applyerDt" id="applyerDt"  disabled="disabled" type="text" class="ui-datepicker" value="${now}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">违约类型</div>
                <div class="field">

                    <select name="breachTypCd" id="breachTypCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${breachTypList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">诉讼方式</div>
                <div class="field">

                    <select name="sueWayCd" id="sueWayCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${sueWayList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否有可执行资产</div>
                <div class="field">

                    <select name="isHaveAssCd" id="isHaveAssCd" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${yesNoList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否保全</div>
                <div class="field">

                    <select name="isWell" id="isWell" data-value=" " validate="{required:true,select:true}">
                        <option value=" ">请选择</option>
                        <c:forEach items="${yesNoList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">保全费</div>
                <div class="field">
                    <input name="wellAmt" id="wellAmt" type="text" class="ui-textbox" value=""  >
                    <span class="requiredSymbol" id="wellAmtSpan" >*</span>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">诉讼管辖</div>
                <div class="field">
                    <select name="sueDomainCd" id="sueDomainCd" data-value=" ">
                        <option value=" ">请选择</option>
                        <c:forEach items="${sueDomainList }" var="bk">
                            <option value="${bk.code }">${bk.codeNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="lawyerBox1"  >
                <div class="label">受理法务</div>
                <div class="field">
                    <select name="lawyer1" id="lawyer1" data-value=" " >
                        <option value=" ">请选择</option>
                        <c:forEach items="${usrList1 }" var="bk">
                            <option value="${bk.id }">${bk.refRlNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id="lawyerBox2"  >
                <div class="label">受理法务</div>
                <div class="field">
                    <select name="lawyer2" id="lawyer2" data-value=" " >
                        <option value=" ">请选择</option>
                        <c:forEach items="${usrList2 }" var="bk">
                            <option value="${bk.id }">${bk.refRlNm }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">诉讼申请说明</div>
                <div class="field">
                    <textarea name="lawyerRem" id="lawyerRem" rows="3" class="l-textarea" style="width:98%" value="" ></textarea>
                </div>
            </div>


            <div class="fieldBox col_100" id="uploadBox">
                <div class="label">资料上传</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                        <jsp:param name="filePath" value="sue"/>
                    </jsp:include>
                </div>
            </div>
            <div class="fieldBox col_100" id="fileModify">
                <div class="label">资料</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysUlFileRecListDetail.jsp" flush="true" >
                        <jsp:param name="pkId" value="${applyId }"/>
                        <jsp:param name="tabNm" value=""/>
                    </jsp:include>
                </div>
            </div>
        </div>
        <div class="sqPanel" style="margin-bottom: 5px;">
            <div class="sqPanel_head" style="height:35px;">
                <table class="table_full">
                    <tr>
                        <td><span >---基本信息---</span></td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="bscGrid" class="sq-grid"></div>

        <div class="sqPanel" style="margin-bottom: 5px;">
            <div class="sqPanel_head" style="height:35px;">
                <table class="table_full">
                    <tr>
                        <td><span >---账单信息---</span></td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="billGrid" class="sq-grid" style="height:200px"></div>

        <div class="btnsBox">
            <span id="saveNewAcc_Btn" class="sq-button sq-button-hasicon l-dialog-btn-ok"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
<script type="text/javascript">
    var lawyerNeedFlag = '${lawyerNeedFlag}';
    var applyId = '${applyId}';
    var dataId = '${dataId}';
    var viewFlag = '${viewFlag}';
    var taskFlag = '${taskFlag}';
    var rmSvBtn = '${rmSvBtn}';
    $(function () {
        $("#addAcc_form").ligerForm({validate:true});
        liger.get("applyerDt").setDisabled();
        $("#lawyerBox1").hide();
        $("#lawyerBox2").hide();
        $("#wellAmtSpan").hide();

        if(StringUtils.isNotEmpty(applyId)){
            initEdit();
        }
        if(StringUtils.isNotEmpty(viewFlag)){
            initView();
        }
        if ('1' == rmSvBtn) {
            $("#saveNewAcc_Btn").hide();
        }
    });
    /**
     * 仅查看
     * */
    function initView(){
        $("#saveNewAcc_Btn").hide();
        $("#sueDomainCd").ligerGetComboBoxManager().setDisabled();
        $("#lawyer1").ligerGetComboBoxManager().setDisabled();
        $("#lawyer2").ligerGetComboBoxManager().setDisabled();
    }
    /**
     * 初始化编辑页面的值
     */
    function initEdit(){
        $("#applyerNm").val('${dto.applyerNm}');
        $("#applyerPhone").val('${dto.applyerPhone}');
        $("#applyerDt").val('${dto.applyerDt}');
        $("#breachTypCd").ligerGetComboBoxManager().setValue('${dto.breachTypCd}')
        $("#sueWayCd").ligerGetComboBoxManager().setValue('${dto.sueWayCd}')
        $("#isHaveAssCd").ligerGetComboBoxManager().setValue('${dto.isHaveAssCd}')
        $("#isWell").ligerGetComboBoxManager().setValue('${dto.isWell}')
        $("#wellAmt").val('${dto.wellAmt}');
        var sudDomainCd = '${dto.sueDomainCd}';
        $("#sueDomainCd").ligerGetComboBoxManager().setValue(sudDomainCd);
        if(StringUtils.isNotEmpty(sudDomainCd) && sudDomainCd =="0001"){
            $("#lawyerBox1").show();
            $("#lawyer1").ligerGetComboBoxManager().setValue('${dto.lawyerId}');
        }else{
            $("#lawyerBox2").show();
            $("#lawyer2").ligerGetComboBoxManager().setValue('${dto.lawyerId}');
        }
        $("#lawyerRem").val('${dto.lawyerRem}');
        initEditAble();

    }

    /**
     *  设置编辑页面不能编辑的东西
     */
    function initEditAble(){
        liger.get("applyerPhone").setDisabled();
        $("#breachTypCd").ligerGetComboBoxManager().setDisabled();
        $("#sueWayCd").ligerGetComboBoxManager().setDisabled();
        $("#isHaveAssCd").ligerGetComboBoxManager().setDisabled();
        $("#isWell").ligerGetComboBoxManager().setDisabled()
        liger.get("wellAmt").setDisabled();
        $("#lawyerRem").attr("disabled",true);
        $("#uploadBox").hide();
    }
    $("#saveNewAcc_Btn").click(function(){
        if(validWellAmt){
            var wellAmt = $("#wellAmt").val();
            if(StringUtils.isEmpty(wellAmt)){
                $.ligerDialog.error('请填写保全费！');
                return false;
            }
        }
        // 受理律师
        var lawyerId = $("#lawyerId").val();
        // 诉讼管辖
        var sueDomainCd = $("#sueDomainCd").val();
        if ('2' == taskFlag) {
            // 贷后管理中心审批
            if (StringUtils.isEmpty(sueDomainCd)) {
                $.ligerDialog.error('请选择诉讼管辖！');
                return false;
            } else if ('0002' == sueDomainCd) {
                // 属地
                if (StringUtils.isEmpty(lawyerId)) {
                    $.ligerDialog.error('请选择受理法务！');
                    return false;
                }
            }
        } else if ('4' == taskFlag) {
            // 风险管理部审批
            if (StringUtils.isEmpty(sueDomainCd)) {
                $.ligerDialog.error('请选择诉讼管辖！');
                return false;
            } else {
                if (StringUtils.isEmpty(lawyerId)) {
                    $.ligerDialog.error('请选择受理法务！');
                    return false;
                }
            }
        }

        var waiting = $.ligerDialog.waitting('正在保存中,请稍候...');
        var ligerForm = liger.get("addAcc_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            waiting.close();
            return false; //验证不通过，不执行以下代码
        }
        var uploadParam = JSON.stringify(getUploadResultParams());
        var data = ligerForm.getData();
        data['uploadParam'] = uploadParam;
        data['dataId'] = dataId;
        data['dataTable'] = dataTable;

        if(StringUtils.isNotEmpty(lawyerNeedFlag) ){
            if(StringUtils.isEmpty(lawyerId) ){
                $.ligerDialog.error('请选择受理律师！');
                return false;
            }
        }
        data['lawyerId'] = lawyerId;
        data['lawyerNm'] = $("#lawyerNm").val();
        if(applyId){
            data['id'] = applyId;
        }
        var dtlList = bscGrid.getData();
        if(CollectionUtils.isNotEmpty(dtlList)){
            for(var dtl of dtlList){
                if(dtl.isYQ==0){
                	if(StringUtils.isEmpty(dtl.isGpsOnline) || StringUtils.isEmpty(dtl.useTmLimit)){
                        $.ligerDialog.error('您有必填项未维护：GPS在线信息或者使用期限！')
                        waiting.close();
                        return false;
                    }
                }
            }
        }
        data['dtlList'] = JSON.stringify(dtlList);
        var url = '<%=path%>/sue/sueApplyInfo/saveOrUpdate.do';

        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            success:function(data){
                waiting.close();
                var success = data.success;
                if(success == "1" && StringUtils.isEmpty(applyId)){
                    $.ligerDialog.success('保存完毕',"提示",function(){
                        var callback = GET_W2Wcallback();
                        callback();
                        Remove_navTab();
                    })
                }else if(success == "1"){
                    $.ligerDialog.success('保存完毕');
                }else{
                    $.ligerDialog.error(data.info)
                }

            }
        });
    })
    var validWellAmt = false;
    $("#isWell").change(function(){
        var val = $(this).val();
        if(StringUtils.isNotEmpty(val) && val=="1"){
            validWellAmt = true;
            $("#wellAmtSpan").show();
        }else{
            validWellAmt =false;
            $("#wellAmtSpan").hide();
        }
    });
    $("#sueDomainCd").change(function(){
        var val = $(this).val();
        if(StringUtils.isNotEmpty(val) && val == "0001"){
            $("#lawyer1").val("");
            $("#lawyerBox1").show();
            $("#lawyerBox2").hide();
        }else{
            $("#lawyer2").val("");
            $("#lawyerBox2").show();
            $("#lawyerBox1").hide();
        }
        $("#lawyerId").val();
        $("#lawyerNm").val();

    });

    $("#lawyer1").change(lawyerChange);
    $("#lawyer2").change(lawyerChange)
    function lawyerChange(){
        var val = $(this).val();
        var text = $(this).find("option:selected").text();
        if(StringUtils.isNotEmpty(val)){
            $("#lawyerId").val(val);
            $("#lawyerNm").val(text);
        }else{
            $("#lawyerId").val("");
            $("#lawyerNm").val("");
        }
    }

    /**
     * 支付表链接
     * @param paySchId
     */
    function showPaySchDetail(paySchId){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/risk/ovdCollect/getPayInfo.do?paySchId='+paySchId,
            success: function (msg) {
                if (msg.success == 1) {
                    Add_navTab('tab_prj_quat_prps'+paySchId,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+msg.data.prjId+'&id='+paySchId+'&prjPrdDtlId='+msg.data.prjPrdDtlId+'&prjPrdId='+msg.data.prjPrdId+'&detailFlag=true');
                }
            }
        });
    }

    // 客户详情页面
    function showDetail(_id){
        parent.parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/showDetail.do?id='+_id);
        <%--parent.pageInTab.addTabItem({tabid:'tab_customer_np_detail'+_id,text:'客户详情',url:'<%=path%>/customer/cstbscinfo/showDetail.do?id='+_id});--%>
    }

</script>


<script>
    var dataTable="PRJ_BSC_INFO"
    var billGrid = null;
    var bscGrid = null;
    var viewFlag = '${viewFlag}';
    var isOnlineList = [{name:'是',value:'1'},{name:'否',value:'0'}];
    $(function () {
        initBillGrid();
        initBscGrid();

    })
    function initBillGrid(){
        var url = '<%=path%>/sue/sueApplyInfo/initBillList.do';
        billGrid = $("#billGrid").ligerGrid({
            url:url,
            parms:{prjId:'${dataId}'},
            method: 'get',
            columns: [
                {display: '支付表号', name: 'paySchNo', width: 150, align: 'right', enabledSort: false,
                    render:function(rowdata){
                        if(null != rowdata.paySchNo && rowdata.paySchNo != ''){
                            return '<a href="javascript:showPaySchDetail('+rowdata.paySchId+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                        }else{
                            return "";
                        }
                    }
                },
                {display: '逾期天数(天)', name: 'overdueDay', width: 150, align: 'right', enabledSort: false},
                {
                    display: '已还租金(元)', name: '', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.paidS01/100);
                    }
                },
                {
                    display: '逾期本金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueS03 / 100);
                    }
                },
                {
                    display: '逾期利息(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueS02 / 100);
                    }
                },
                {
                    display: '逾期租金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueS01 / 100);
                    }
                },
                {
                    display: '罚息(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.s05 / 100);
                    }
                },
                {
                    display: '未来本金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftS03 / 100);
                    }
                },
                {
                    display: '未来利息(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.leftS02 / 100);
                    }
                },
                {
                    display: '履约保证金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee02 / 100);
                    }
                },
                {
                    display: '保险保证金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee11 / 100);
                    }
                },
                {
                    display: '风险保证金(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee33 / 100);
                    }
                },
                {
                    display: '拖车费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee104 / 100);
                    }
                },
                {
                    display: '停车费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee106 / 100);
                    }
                },
                {
                    display: '维修费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee46 / 100);
                    }
                },
                {
                    display: '迁库费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee402 / 100);
                    }
                },
                {
                    display: '提档过户费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee105 / 100);
                    }
                },
                {
                    display: '违章费(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee401 / 100);
                    }
                },
                {
                    display: '留购价(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee07 / 100);
                    }
                },
                {
                    display: '其他费用(元)', name: '', width: 150, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fee107 / 100);
                    }
                },

            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '200',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            rownumbers: false,  //显示序号
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            }
        })
    }
    function initBscGrid(){
        var url = '<%=path%>/sue/sueApplyInfo/initPrjPrdDtlList.do';
        var option = {
            url:url,
            parms:{prjId:'${dataId}',applyId:applyId},
            method: 'get',
            columns: [

                {display: '承租人', name: 'cstName', width: 150, align: 'right', enabledSort: false,
                    render:function(rowdata){
                        if(null != rowdata.cstName && rowdata.cstName != ''){
                            return  '<a href="javascript:showDetail('+rowdata.cstId+')"'+'class="link">'+rowdata.cstName+'</a>';
                        }else{
                            return "";
                        }
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 150, align: 'right', enabledSort: false,
                    render:function(rowdata){
                        if(null != rowdata.paySchNo && rowdata.paySchNo != ''){
                            return '<a href="javascript:showPaySchDetail('+rowdata.paySchId+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                        }else{
                            return "";
                        }
                    }
                },
                {display: '设备名称', name: 'prdNm', width: 150, align: 'right', enabledSort: false},
                {display: '设备型号', name: 'prdMdl', width: 150, align: 'right', enabledSort: false},
                {display: 'GPS是否在线<span style="color:red">*</span>', name: 'isGpsOnline', width: 150, align: 'right', enabledSort: false,
                    editor: { type: 'select', data: isOnlineList, valueField: 'value', textField: 'name' }, render: function (item)
                    {
                        for (var i = 0; i < isOnlineList.length; i++)
                        {
                            if (isOnlineList[i]['value'] == item.isGpsOnline)
                                return isOnlineList[i]['name']
                        }
                        return "请选择";
                    }
                },
                {display: '使用期限(月)', name: 'useTmLimit', width: 150, align: 'right', enabledSort: false,  editor:{type:'text'}},
                {display: '是否拖回', name: 'isBack', width: 150, align: 'right', enabledSort: false},
                {display: '实际拖回时间', name: 'backDtString', width: 150, align: 'right', enabledSort: false},
                {
                    display: '设备款(元)', name: '', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.money/100);
                    }
                },
                {display: '是否YQ', name: 'isYQ', width: 0, align: 'right', enabledSort: false ,hide:true}
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '200',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledEdit: true,
            rownumbers: false,  //显示序号
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            }
        }
        if(applyId){
            option.enabledEdit = false;
        }
        bscGrid = $("#bscGrid").ligerGrid(option);
        bscGrid.setHeight(100);
    }
</script>
</body>
</html>
